﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for MySecurity
/// </summary>
public static class MySecurity
{
  static char[] P = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
                           'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ','-'};
  static int z = 38;
  public static int k = 12;
  private static int Get_Ma(char input)
  {
    int oupt = 0;
    for (int i = 0; i < z; i++)
    {
      if (input == P[i]) { oupt = i; break; }
    }
    return oupt;
  }
  public static string MaHoa(string input, int k)
  {
    input = input.ToUpper();
    int count = input.Length;
    string output = "";
    for (int i = 0; i < count; i++)
    {
      for (int j = 0; j < z; j++)
      {
        if (input[i] == P[j])
        {
          int getma = Get_Ma(input[i]);
          int temp = (j + k) % z;         
          output += P[temp].ToString();
          break;
        }
      }
    }
    return output;
  }
  public static string GiaiMa(string input, int k)
  {
    input = input.ToUpper();
    int count = input.Length; 
    string output = "";
    for (int i = 0; i < count; i++)
    {
      for (int j = 0; j < z; j++)
      {
        if (input[i] == P[j])
        {
          int getma = Get_Ma(input[i]);
          int temp = (j + z - k) % z;          
          output += P[temp].ToString();
          break;
        }
      }
    }
    return output;
  }
}